﻿using OpenTK.Graphics.OpenGL4;

namespace TrinityEngine
{
    public class SpriteRenderer : Renderer
    {
        public Sprite sprite;

        public bool flipX;

        public bool flipY;

        public Vector2 size;

        public SpriteRenderer(Sprite sprite)
        {
            this.sprite = sprite;
            flipX = false;
            flipY = false;
            size = Vector2.one;
        }

        protected override void Update()
        {
            base.Update();

            /*_origin = new Vector2(sprite.texture.width * pivot.x, sprite.texture.height * pivot.y);*/
        }

        protected override void Render()
        {
            if (sprite == null)
            {
                return;
            }

            /*SpriteEffects effects = SpriteEffects.None;
            float flipRotation = 0f;
            if (flipX && !flipY)
            {
                effects = SpriteEffects.FlipHorizontally;
            }
            else if (flipY && !flipX)
            {
                effects = SpriteEffects.FlipVertically;
            }
            else if (flipX && flipY)
            {
                flipRotation = 180f;
            }

            Engine.Instance.batch.Draw(
                sprite.texture,
                new Vector2(_position.x, -_position.y),
                null,
                tint,
                (_rotation + flipRotation) * Mathf.Deg2Rad,
                _origin,
                size * _scale / sprite.pixelPerUnit,
                effects,
                sortingLayer);*/

            Quad.Use();
            /*sprite.texture.Use();*/
            /*material.Use();*/
            /*_mvp = sprite.GetSpriteMatrix() * transform.GetModelMatrix() * Camera.main.GetViewMatrix() * Camera.main.GetProjectionMatrix();
            GL.UniformMatrix4(_mvpLocation, true, ref _mvp);
            GL.DrawArrays(PrimitiveType.Triangles, 0, 6);*/
        }

        protected override void OnDestroy()
        {
            sprite = null;
        }
    }
}
